/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyGUI;
import MyDatabaseHandler.DatabaseHandler;
import java.io.*;
import java.net.*;
import javax.net.ssl.SSLServerSocket;
/**
 *
 * @author hauhaulovely
 */

class ChildThread extends Thread {
        int port = 2002;
        ServerSocket ss;
        Socket s;
	ChildThread() {
		super("Child Thread");
        }
	
	public void run() {
		try {
			ss = new ServerSocket(port);
                        s = ss.accept();
                        System.out.print("Connected !");
                        DatabaseHandler db = new DatabaseHandler();
                        
                        //Chuyen object thanh mang bytes
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        ObjectOutput out = new ObjectOutputStream(bos);
                        byte[] Bytes = bos.toByteArray();
                        System.out.print(Bytes.length);
                        bos.close();
                        out.close();
                        //Chuyen mang bytes
                        
                        OutputStream os = s.getOutputStream();
                        DataOutputStream dos = new DataOutputStream(os);
                        dos.writeInt(Bytes.length);
                        if(Bytes.length > 0)
                        {
                            dos.write(Bytes, 0, Bytes.length);
                        }
                        os.close();
                        dos.close();
                        while(true)
                        {
                            
                        }
		} catch (Exception e) {
			System.out.println("Error from child thread !");
		}
		
	}
	
}
